//
//  NextCheckItemView.m
//  yilutongxing
//
//  Created by T&J on 2017/12/5.
//  Copyright © 2017年 YZE. All rights reserved.
//

#import "NextCheckItemView.h"
#import <QMUIFloatLayoutView.h>
#import "RPNextCheckItem.h"
#import "YZEUIButtonChoose.h"

@implementation NextCheckItemView

-(instancetype)initWithData:(NSArray *)checkItemArr{
    self = [super init];
    if (self) {
        [self setFrame:CGRectMake(30, 0, SCREEN_WIDTH - 60, 8)];
        UIEdgeInsets padbox = UIEdgeInsetsMake(0, 0, 8, 6);
        CGFloat base_y = 6;
        for (int i=0; i<checkItemArr.count; i++) {
            NSDictionary *item = (NSDictionary*)checkItemArr[i];
            UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(0, base_y, 200, 20)];
            [title setTextColor:COLOR(100, 100, 100)];
            title.text = item[@"item_type"];
            [self addSubview:title];
            
            base_y += title.frame.size.height + 10;
            
            NSArray *subitem_arr = item[@"subitems"];
            QMUIFloatLayoutView *floatbox = [[QMUIFloatLayoutView alloc]init];
            floatbox.itemMargins = padbox;
            [self addSubview:floatbox];
            for (int j=0; j<subitem_arr.count; j++) {
                NSString *subitem = subitem_arr[j];
                YZEUIButtonChoose *btn = [[YZEUIButtonChoose alloc]initWithTitle:subitem];
                [btn setSelected:YES];
                [btn setUserInteractionEnabled:NO];
                [floatbox addSubview:btn];
            }
            CGSize boxsize = [floatbox sizeThatFits:CGSizeMake(self.frame.size.width, CGFLOAT_MAX)];
            [floatbox setFrame:CGRectMake(6, base_y, boxsize.width, boxsize.height)];
            
            base_y += boxsize.height + 8;
        }
        
        CGRect tframe = self.frame;
        tframe.size.height = base_y;
        [self setFrame:tframe];
        self.height = base_y;
    }
    return self;
}

@end
